package com.xuecheng.media.api;

import com.xuecheng.base.model.RestResponse;
import com.xuecheng.media.model.po.MediaFiles;
import com.xuecheng.media.service.MediaFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shiminghui
 * @date 2024/9/1 16:32
 * @description: TODO
 */
@RestController
@Api(value = "媒资文件管理接口")
@RequestMapping("open")
@Slf4j
@RequiredArgsConstructor
public class MediaOpenController {

    private final MediaFileService mediaFileService;

    @ApiOperation("预览文件")
    @GetMapping("/preview/{mediaId}")
    public RestResponse<String> getPlayUrlByMediaId(@PathVariable String mediaId) {
        MediaFiles mediaFiles = mediaFileService.getFileById(mediaId);

        String url = mediaFiles.getUrl();

        if (url == null || url.isEmpty()) {
            return RestResponse.validfail("文件正在处理中");
        }
        return RestResponse.success(url);
    }
}
